package com.dava.helpmywife;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Switch;
import android.widget.Toast;

import com.dava.helpmywife.data.initDataApp;
import com.dava.helpmywife.updata.UpdateUtil;

public class Settings extends Activity {
	private final String tag = "SoftLog";
	private final String PREFERENCES_NAME = "userInfo";
	private Switch isSendMsg;
	private Switch isCall;
	private Switch isAlert;
	private initDataApp data;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);

		Log.i(tag, "start init app setting");
		isSendMsg = (Switch) findViewById(R.id.isSendMessage);
		isCall = (Switch) findViewById(R.id.isCall);
		isAlert = (Switch) findViewById(R.id.isAlert);

		data = (initDataApp) getApplication();

		isSendMsg.setChecked(data.isSendMsg());
		isCall.setChecked(data.isCall());
		isAlert.setChecked(data.isAlert());
		Log.i(tag, "finish init app setting");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.settings, menu);
		return true;
	}

	@Override
	protected void onPause() {
		// 停止的时候自动保存信息
		SharedPreferences preferences = getSharedPreferences(PREFERENCES_NAME,
				Activity.MODE_PRIVATE);
		SharedPreferences.Editor edit = preferences.edit();
		edit.putBoolean("isSendMsg", isSendMsg.isChecked());
		edit.putBoolean("isCall", isCall.isChecked());
		edit.putBoolean("isAlert", isAlert.isChecked());
		edit.commit();
		data.update();
		Log.i(tag, "finish save app setting");
		super.onPause();
	}

	public boolean sendMsgs(View view) {
		Intent intent = new Intent();
		intent.setClass(Settings.this, WriteMsg.class);
		startActivity(intent);
		return false;
	}

	public boolean CallNums(View view) {
		Intent intent = new Intent();
		intent.setClass(Settings.this, CallNums.class);
		startActivity(intent);
		return false;
	}

	public boolean updateVersion(View view) {
		UpdateUtil updateManager = new UpdateUtil(Settings.this);
		updateManager.checkUpdate(true);
		return false;
	}

//	public boolean creatIco(View view){
//		Launcher.createShortCut(Settings.this, R.drawable.ic_launcher,R.string.app_name);
//		return false;
//	}
}
